<?php
/**
 * Created by .
 * User: 小涛.
 * Date: 2018/12/29
 * Time: 10:18
 */

namespace app\admin\model;

use think\Model;
use think\Request;

/**
 * Class Address 会员收货地址
 * @package app\admin\model
 */
class Address extends Model
{
    //会员与会员收货地址的关系
    public function MemberById(){
        return $this -> belongsTo("Member","member_id","id");
    }

    //列表
    public static function listAddress($listRow = 10){
        return self::with("MemberById")
            -> order("id desc")
            -> paginate($listRow, false, [
                "query" => Request::instance() -> param()
            ]);
    }

    //会员列表
    public static function Address($member_id = 0,$row = 10){
        $list = self::with("MemberById")
            -> where(["member_id" => $member_id])
            -> order("is_default desc");
        if($row == 0){
            return $list -> select();
        }
        return $list -> paginate($row, false, [
            "query" => Request::instance() -> param()
        ]);
    }

}